/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaResultados.java
 *
 * Created on 26-feb-2013, 17:24:32
 */
package practica1compi;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Iterator;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.Border;
import org.nfunk.jep.JEP;

/**
 *
 * @author Ebert
 */
public class VentanaResultados extends javax.swing.JFrame {
Interfaz VentanaAnterior;
    /** Creates new form VentanaResultados */
    public VentanaResultados(Interfaz principal) {
        GraficadorClasico(); 
        initComponents();
        VentanaAnterior=principal;
    }
    
    
    
 String texto=" 2x^1+1 ";
    
 public void generarEcuaciones(){
  ecuacion  temporal=null;
    Iterator<ecuacion> puntero=Interfaz.ecuaciones.iterator();
String converecuacion="";
while(puntero.hasNext()){
    converecuacion=" ";
temporal=puntero.next();
int contador=0;
for(int a=temporal.grado;a>0;a--){
   int menos=temporal.abcde.get(contador).indexOf("-");
   if(menos != -1){
converecuacion+= temporal.abcde.get(contador)+"*x^"+a;   
   }
   else{
   converecuacion+= "+"+temporal.abcde.get(contador)+"*x^"+a;
   }
contador++;
}
int menos=temporal.abcde.get(contador).indexOf("-");
   if(menos != -1){
converecuacion+= temporal.abcde.get(contador);   
   }
   else{
   converecuacion+= "+"+temporal.abcde.get(contador)+" ";
   }

list1.add(converecuacion);
//System.out.println(converecuacion);
}
 }
    public void SetText(String textoa){
    texto=textoa;
    }
    public void Actualiza(){
         ZG.repaint();
    }
    
    public void inicializar(){
        String texto="";
        String texto1="";
    String  temporal=null;
    Iterator<String> puntero=Interfaz.Imprimir.iterator();

while(puntero.hasNext()){
temporal=puntero.next();
texto+=temporal+"\n";

}
 String  temporal1=null;
    Iterator<String> puntero1=Interfaz.operacioens.iterator();

while(puntero1.hasNext()){
temporal1=puntero1.next();
texto1+=temporal1+"\n";

}
jTextArea2.setText(texto1);
jTextArea1.setText(texto);
    generarEcuaciones();
    }
 public    JEP miEvaluador;
 boolean    errorEnExpresion; //si hay error de sintaxis en la función
 boolean    errorEnNumero   ; //si hay error de sintaxis en la función
 Font ft10 = new Font("Arial",Font.PLAIN,10);
 Font ft12 = new Font("Arial",Font.PLAIN,12);
 Font ft7  = new Font("Arial",Font.PLAIN,7);
 
 
 
 JPanel ZG; //aquí se va a poner la ZonaGrafica
 JPanel ControlPanel ; //panel para botones y campos de texto,etc 
 
 JPanel DisplayPanel1 = new JPanel(); //aquí se va a poner ZG para obtener un buen borde
 
 JButton BtnGraficar;  
 int Galto,Gancho; //dimesiones de la zona de graficación 
 
 double xmin,xmax,imgx;
 int    x0,y0;           //origen
 int    escalaX,escalaY; 
 final static BasicStroke grosor1 = new BasicStroke(1.5f); //thickness
 final static float dash1[] = {5.0f};
 final static BasicStroke dashed = new BasicStroke(1.0f, 
                                                      BasicStroke.CAP_BUTT, 
                                                      BasicStroke.JOIN_MITER, 
                                                      5.0f, dash1, 0.0f);
 
 
 

public void  GraficadorClasico() 
 { 
     
	 Container Contenedor =new Container(); 
         Contenedor.setBounds(0, 0, 300, 300);
         Contenedor.setVisible(true);
         
	 Gancho = 300;
	 Galto = 300; 
	 ZG = new ZonaGrafica(this); //zona gráfica
	 
	 ControlPanel = new JPanel();
	 DisplayPanel1.setLayout(new BorderLayout());
         DisplayPanel1.setBounds(0, 0, 300, 300);
         DisplayPanel1.setVisible(true);
	 DisplayPanel1.add(ZG, BorderLayout.CENTER); 
	
	    
	 ControlPanel.setLayout(new GridBagLayout()); // como hoja de Excel 
	 GridBagConstraints c = new GridBagConstraints();
	 c.fill = GridBagConstraints.HORIZONTAL;
	
     
	 BtnGraficar = new JButton("Graficar"); 
	 c.gridy = 1; // fila
	 c.gridx = 2; // columna 
	 ControlPanel.add(BtnGraficar,c); 
	 BtnGraficar.setFont(ft12);
	
	 
	
	 
	
	 //Bordes 
	 Border colorline = BorderFactory.createLineBorder(new Color(220,220,220)); 
	 DisplayPanel1.setBorder(colorline); 
	 
	 DisplayPanel1.setPreferredSize( new Dimension(Gancho,Galto)); 
	 ControlPanel.setPreferredSize( new Dimension(60*Gancho/100,30*getSize().height/100));
	 //SP.setPreferredSize( new Dimension(30*Gancho/100,30*getSize().height/100));
	
	 
	
	
	 Contenedor.setLayout(new BorderLayout(1,1)); //aplicar al applet
	 Contenedor.add("Center", DisplayPanel1);
	
	 
	 miEvaluador = new JEP();                     
	 miEvaluador.addStandardFunctions();  //agrega las funciones matematicas comunes
	 miEvaluador.addStandardConstants();  
	 miEvaluador.addComplex();  		
	 miEvaluador.addFunction("sen", new org.nfunk.jep.function.Sine());//habilitar 'sen'			
	 miEvaluador.addVariable("x", 0); 
	 miEvaluador.setImplicitMul(true); //permite 2x en vez de 2*x
	 escalaX=30;
	 escalaY=30;
	 x0=Gancho/2;
	 y0=Galto/2;
	 
	 	ManejadorDeEvento ManejadorDevt = new  ManejadorDeEvento(this);		 	
		
		BtnGraficar.addActionListener(ManejadorDevt);
		
		
	this.add(Contenedor)	;
 }	
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        list1 = new java.awt.List();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Cerrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        list1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                list1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Graficar");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel1)))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(19, 19, 19)
                .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(73, Short.MAX_VALUE))
        );

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jLabel2.setText("funcion Print");

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        jLabel3.setText("funcion Operacion");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 189, Short.MAX_VALUE)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(200, 200, 200))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton1)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
this.VentanaAnterior.setVisible(true);
this.setVisible(false);// TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed

private void list1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_list1ActionPerformed

    
this.SetText(this.list1.getSelectedItem());
this.Actualiza();    
    // TODO add your handling code here:
}//GEN-LAST:event_list1ActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private java.awt.List list1;
    // End of variables declaration//GEN-END:variables
}
